import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
headers = {'Cookie':
	'BAIDUID=53F93412B79BB9CC8DCD799896DB46E3:FG=1; BIDUPSID=53F93412B79BB9CC9E97DA0937C2E88E; PSTM=1615953788; __yjs_duid=1_1cbcbc35a8a47b719fea004b285111aa1631873628279; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; BDRCVFR[Fc9oatPmwxn]=srT4swvGNE6uzdhUL68mv3; delPer=0; PSINO=2; H_PS_PSSID=35740_35105_31660_35732_35488_34584_35490_34812_35322_26350_35724_22158; BA_HECTOR=a1a40h8k810l8501vr1gudi1s0r; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1642514478,1642514498,1642514529,1642516263; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1642516423; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; APPGUIDE_10_0_2=1; ab_sr=1.0.1_NGU0ZmU5ZjU0N2RjMTczMWI3YTUyMTliNzQwMjI1MWI3MzJmMjg1NzZjODNlNWQ4MTM2Y2RhN2UwZGFjMDczZmVlY2NlMDYyZWMyNzYxOTk2NmNkYTM2N2ZhYzEzYTk4'
    }

data = {
'from':'en',
'to':'zh',
'query':'love',
'transtype':'realtime',
'simple_means_flag':'3',
'sign':'198772.518981',
'token':'9aaefc09e2b83b4dadaef0f0e175c199',
'domain':'common'
}
#post请求参数必须进行编码调用encode方法
data = urllib.parse.urlencode(data).encode('utf-8')
#请求对象的定制
request = urllib.request.Request(url=url,data=data,headers=headers)
#模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

#获取响应的数据
content = response.read().decode('utf-8')


import json
obj = json.loads(content)
print(obj)
